{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, 0, 0, 0],\n",
       "       [0, 0, 0, 0, 0, 0],\n",
       "       [0, 0, 0, 0, 0, 0],\n",
       "       [0, 0, 0, 0, 0, 0],\n",
       "       [0, 0, 0, 0, 0, 0],\n",
       "       [0, 0, 0, 0, 0, 0]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.full((6,6),0)\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1, 1, 1, 1],\n",
       "       [1, 0, 0, 0, 0, 1],\n",
       "       [1, 0, 0, 0, 0, 1],\n",
       "       [1, 0, 0, 0, 0, 1],\n",
       "       [1, 0, 0, 0, 0, 1],\n",
       "       [1, 1, 1, 1, 1, 1]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr[[0,5],]=1\n",
    "arr[:,[0,5]]=1\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[1, 1, 1, 1, 1, 1],\n",
       "        [1, 0, 0, 0, 0, 1],\n",
       "        [1, 0, 0, 0, 0, 1],\n",
       "        [1, 0, 0, 0, 0, 1],\n",
       "        [1, 0, 0, 0, 0, 1],\n",
       "        [1, 1, 1, 1, 1, 1]])"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.full((6,6),0)\n",
    "arr[[0,5],]=1\n",
    "arr[:,[0,5]]=1\n",
    "arr = np.matrix(arr)\n",
    "arr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[5, 5],\n",
       "        [5, 5]])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2 = np.full((2,2),5)\n",
    "mat1=np.matrix(arr2)\n",
    "mat1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[0, 1],\n",
       "        [2, 3]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr2_1 = np.arange(4).reshape(2,2)\n",
    "mat2=np.matrix(arr2_1)\n",
    "mat2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[10, 20],\n",
       "        [10, 20]])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mat1*mat2                                                           "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 0,  1,  2,  3,  4,  5],\n",
       "        [ 6,  7,  8,  9, 10, 11],\n",
       "        [12, 13, 14, 15, 16, 17],\n",
       "        [18, 19, 20, 21, 22, 23]])"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.arange(24).reshape(4,6)\n",
    "a = np.matrix(a)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[0, 1, 2, 3, 4, 5]])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = np.arange(6).reshape(1,6)\n",
    "b = np.matrix(b)\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "shape = a+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "matrix([[ 0,  2,  4,  6,  8, 10],\n",
       "        [ 6,  8, 10, 12, 14, 16],\n",
       "        [12, 14, 16, 18, 20, 22],\n",
       "        [18, 20, 22, 24, 26, 28]])"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5.1, 4.9, 4.7, 4.6, 5. , 5.4, 4.6, 5. , 4.4, 4.9, 5.4, 4.8, 4.8,\n",
       "       4.3, 5.8, 5.7, 5.4, 5.1, 5.7, 5.1, 5.4, 5.1, 4.6, 5.1, 4.8, 5. ,\n",
       "       5. , 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5. , 5.5, 4.9, 4.4,\n",
       "       5.1, 5. , 4.5, 4.4, 5. , 5.1, 4.8, 5.1, 4.6, 5.3, 5. , 7. , 6.4,\n",
       "       6.9, 5.5, 6.5, 5.7, 6.3, 4.9, 6.6, 5.2, 5. , 5.9, 6. , 6.1, 5.6,\n",
       "       6.7, 5.6, 5.8, 6.2, 5.6, 5.9, 6.1, 6.3, 6.1, 6.4, 6.6, 6.8, 6.7,\n",
       "       6. , 5.7, 5.5, 5.5, 5.8, 6. , 5.4, 6. , 6.7, 6.3, 5.6, 5.5, 5.5,\n",
       "       6.1, 5.8, 5. , 5.6, 5.7, 5.7, 6.2, 5.1, 5.7, 6.3, 5.8, 7.1, 6.3,\n",
       "       6.5, 7.6, 4.9, 7.3, 6.7, 7.2, 6.5, 6.4, 6.8, 5.7, 5.8, 6.4, 6.5,\n",
       "       7.7, 7.7, 6. , 6.9, 5.6, 7.7, 6.3, 6.7, 7.2, 6.2, 6.1, 6.4, 7.2,\n",
       "       7.4, 7.9, 6.4, 6.3, 6.1, 7.7, 6.3, 6.4, 6. , 6.9, 6.7, 6.9, 5.8,\n",
       "       6.8, 6.7, 6.7, 6.3, 6.5, 6.2, 5.9])"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.loadtxt(r'D:\\新建文件夹\\iris_sepal_length.csv', delimiter=',' , unpack=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "iris = np.loadtxt(r'D:\\新建文件夹\\iris_sepal_length.csv', delimiter=',' , unpack=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5.1, 4.9, 4.7, 4.6, 5. , 5.4, 4.6, 5. , 4.4, 4.9, 5.4, 4.8, 4.8,\n",
       "       4.3, 5.8, 5.7, 5.4, 5.1, 5.7, 5.1, 5.4, 5.1, 4.6, 5.1, 4.8, 5. ,\n",
       "       5. , 5.2, 5.2, 4.7, 4.8, 5.4, 5.2, 5.5, 4.9, 5. , 5.5, 4.9, 4.4,\n",
       "       5.1, 5. , 4.5, 4.4, 5. , 5.1, 4.8, 5.1, 4.6, 5.3, 5. , 7. , 6.4,\n",
       "       6.9, 5.5, 6.5, 5.7, 6.3, 4.9, 6.6, 5.2, 5. , 5.9, 6. , 6.1, 5.6,\n",
       "       6.7, 5.6, 5.8, 6.2, 5.6, 5.9, 6.1, 6.3, 6.1, 6.4, 6.6, 6.8, 6.7,\n",
       "       6. , 5.7, 5.5, 5.5, 5.8, 6. , 5.4, 6. , 6.7, 6.3, 5.6, 5.5, 5.5,\n",
       "       6.1, 5.8, 5. , 5.6, 5.7, 5.7, 6.2, 5.1, 5.7, 6.3, 5.8, 7.1, 6.3,\n",
       "       6.5, 7.6, 4.9, 7.3, 6.7, 7.2, 6.5, 6.4, 6.8, 5.7, 5.8, 6.4, 6.5,\n",
       "       7.7, 7.7, 6. , 6.9, 5.6, 7.7, 6.3, 6.7, 7.2, 6.2, 6.1, 6.4, 7.2,\n",
       "       7.4, 7.9, 6.4, 6.3, 6.1, 7.7, 6.3, 6.4, 6. , 6.9, 6.7, 6.9, 5.8,\n",
       "       6.8, 6.7, 6.7, 6.3, 6.5, 6.2, 5.9])"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iris"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "iris.sort(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "iris.sort(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4.3, 4.4, 4.4, 4.4, 4.5, 4.6, 4.6, 4.6, 4.6, 4.7, 4.7, 4.8, 4.8,\n",
       "       4.8, 4.8, 4.8, 4.9, 4.9, 4.9, 4.9, 4.9, 4.9, 5. , 5. , 5. , 5. ,\n",
       "       5. , 5. , 5. , 5. , 5. , 5. , 5.1, 5.1, 5.1, 5.1, 5.1, 5.1, 5.1,\n",
       "       5.1, 5.1, 5.2, 5.2, 5.2, 5.2, 5.3, 5.4, 5.4, 5.4, 5.4, 5.4, 5.4,\n",
       "       5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6,\n",
       "       5.7, 5.7, 5.7, 5.7, 5.7, 5.7, 5.7, 5.7, 5.8, 5.8, 5.8, 5.8, 5.8,\n",
       "       5.8, 5.8, 5.9, 5.9, 5.9, 6. , 6. , 6. , 6. , 6. , 6. , 6.1, 6.1,\n",
       "       6.1, 6.1, 6.1, 6.1, 6.2, 6.2, 6.2, 6.2, 6.3, 6.3, 6.3, 6.3, 6.3,\n",
       "       6.3, 6.3, 6.3, 6.3, 6.4, 6.4, 6.4, 6.4, 6.4, 6.4, 6.4, 6.5, 6.5,\n",
       "       6.5, 6.5, 6.5, 6.6, 6.6, 6.7, 6.7, 6.7, 6.7, 6.7, 6.7, 6.7, 6.7,\n",
       "       6.8, 6.8, 6.8, 6.9, 6.9, 6.9, 6.9, 7. , 7.1, 7.2, 7.2, 7.2, 7.3,\n",
       "       7.4, 7.6, 7.7, 7.7, 7.7, 7.7, 7.9])"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iris"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5. , 5.1, 5.2, 5.3, 5.4, 5.5,\n",
       "       5.6, 5.7, 5.8, 5.9, 6. , 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8,\n",
       "       6.9, 7. , 7.1, 7.2, 7.3, 7.4, 7.6, 7.7, 7.9])"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "876.5"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.843333333333334"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8253012917851409"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6811222222222223"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.var(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4.3"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.min(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.9"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.max(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  4.3,   8.7,  13.1,  17.5,  22. ,  26.6,  31.2,  35.8,  40.4,\n",
       "        45.1,  49.8,  54.6,  59.4,  64.2,  69. ,  73.8,  78.7,  83.6,\n",
       "        88.5,  93.4,  98.3, 103.2, 108.2, 113.2, 118.2, 123.2, 128.2,\n",
       "       133.2, 138.2, 143.2, 148.2, 153.2, 158.3, 163.4, 168.5, 173.6,\n",
       "       178.7, 183.8, 188.9, 194. , 199.1, 204.3, 209.5, 214.7, 219.9,\n",
       "       225.2, 230.6, 236. , 241.4, 246.8, 252.2, 257.6, 263.1, 268.6,\n",
       "       274.1, 279.6, 285.1, 290.6, 296.1, 301.7, 307.3, 312.9, 318.5,\n",
       "       324.1, 329.7, 335.4, 341.1, 346.8, 352.5, 358.2, 363.9, 369.6,\n",
       "       375.3, 381.1, 386.9, 392.7, 398.5, 404.3, 410.1, 415.9, 421.8,\n",
       "       427.7, 433.6, 439.6, 445.6, 451.6, 457.6, 463.6, 469.6, 475.7,\n",
       "       481.8, 487.9, 494. , 500.1, 506.2, 512.4, 518.6, 524.8, 531. ,\n",
       "       537.3, 543.6, 549.9, 556.2, 562.5, 568.8, 575.1, 581.4, 587.7,\n",
       "       594.1, 600.5, 606.9, 613.3, 619.7, 626.1, 632.5, 639. , 645.5,\n",
       "       652. , 658.5, 665. , 671.6, 678.2, 684.9, 691.6, 698.3, 705. ,\n",
       "       711.7, 718.4, 725.1, 731.8, 738.6, 745.4, 752.2, 759.1, 766. ,\n",
       "       772.9, 779.8, 786.8, 793.9, 801.1, 808.3, 815.5, 822.8, 830.2,\n",
       "       837.8, 845.5, 853.2, 860.9, 868.6, 876.5])"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.cumsum(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4.30000000e+000, 1.89200000e+001, 8.32480000e+001, 3.66291200e+002,\n",
       "       1.64831040e+003, 7.58222784e+003, 3.48782481e+004, 1.60439941e+005,\n",
       "       7.38023729e+005, 3.46871153e+006, 1.63029442e+007, 7.82541320e+007,\n",
       "       3.75619834e+008, 1.80297520e+009, 8.65428097e+009, 4.15405487e+010,\n",
       "       2.03548688e+011, 9.97388573e+011, 4.88720401e+012, 2.39472996e+013,\n",
       "       1.17341768e+014, 5.74974664e+014, 2.87487332e+015, 1.43743666e+016,\n",
       "       7.18718331e+016, 3.59359165e+017, 1.79679583e+018, 8.98397913e+018,\n",
       "       4.49198957e+019, 2.24599478e+020, 1.12299739e+021, 5.61498696e+021,\n",
       "       2.86364335e+022, 1.46045811e+023, 7.44833635e+023, 3.79865154e+024,\n",
       "       1.93731228e+025, 9.88029265e+025, 5.03894925e+026, 2.56986412e+027,\n",
       "       1.31063070e+028, 6.81527964e+028, 3.54394541e+029, 1.84285162e+030,\n",
       "       9.58282840e+030, 5.07889905e+031, 2.74260549e+032, 1.48100696e+033,\n",
       "       7.99743760e+033, 4.31861631e+034, 2.33205280e+035, 1.25930851e+036,\n",
       "       6.92619683e+036, 3.80940826e+037, 2.09517454e+038, 1.15234600e+039,\n",
       "       6.33790299e+039, 3.48584664e+040, 1.91721565e+041, 1.07364077e+042,\n",
       "       6.01238829e+042, 3.36693744e+043, 1.88548497e+044, 1.05587158e+045,\n",
       "       5.91288086e+045, 3.37034209e+046, 1.92109499e+047, 1.09502414e+048,\n",
       "       6.24163763e+048, 3.55773345e+049, 2.02790806e+050, 1.15590760e+051,\n",
       "       6.58867330e+051, 3.82143051e+052, 2.21642970e+053, 1.28552923e+054,\n",
       "       7.45606951e+054, 4.32452031e+055, 2.50822178e+056, 1.45476863e+057,\n",
       "       8.58313494e+057, 5.06404961e+058, 2.98778927e+059, 1.79267356e+060,\n",
       "       1.07560414e+061, 6.45362483e+061, 3.87217490e+062, 2.32330494e+063,\n",
       "       1.39398296e+064, 8.50329607e+064, 5.18701060e+065, 3.16407647e+066,\n",
       "       1.93008665e+067, 1.17735285e+068, 7.18185241e+068, 4.45274849e+069,\n",
       "       2.76070407e+070, 1.71163652e+071, 1.06121464e+072, 6.68565225e+072,\n",
       "       4.21196092e+073, 2.65353538e+074, 1.67172729e+075, 1.05318819e+076,\n",
       "       6.63508561e+076, 4.18010393e+077, 2.63346548e+078, 1.65908325e+079,\n",
       "       1.06181328e+080, 6.79560500e+080, 4.34918720e+081, 2.78347981e+082,\n",
       "       1.78142708e+083, 1.14011333e+084, 7.29672530e+084, 4.74287145e+085,\n",
       "       3.08286644e+086, 2.00386319e+087, 1.30251107e+088, 8.46632196e+088,\n",
       "       5.58777250e+089, 3.68792985e+090, 2.47091300e+091, 1.65551171e+092,\n",
       "       1.10919284e+093, 7.43159206e+093, 4.97916668e+094, 3.33604167e+095,\n",
       "       2.23514792e+096, 1.49754911e+097, 1.01833339e+098, 6.92466707e+098,\n",
       "       4.70877361e+099, 3.24905379e+100, 2.24184712e+101, 1.54687451e+102,\n",
       "       1.06734341e+103, 7.47140388e+103, 5.30469676e+104, 3.81938167e+105,\n",
       "       2.74995480e+106, 1.97996746e+107, 1.44537624e+108, 1.06957842e+109,\n",
       "       8.12879599e+109, 6.25917291e+110, 4.81956314e+111, 3.71106362e+112,\n",
       "       2.85751899e+113, 2.25744000e+114])"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.cumprod(iris)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
